Skip to content

feat(issues): infer project platform if not set #95402

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 20 commits into from
Jul 16, 2025

Conversation

cvxluo
Copy link
Contributor

@cvxluo cvxluo commented Jul 13, 2025

If a project ends up with no platform (e.g. by API creation), we attempt to infer it from its next event by setting the project's platform to the event's platform.

Related:

@github-actions github-actions bot added the Scope: Backend Automatically applied to PRs that change backend components label Jul 13, 2025
Copy link

codecov bot commented Jul 13, 2025

Codecov Report

Attention: Patch coverage is 96.29630% with 1 line in your changes missing coverage. Please review.

✅ All tests successful. No failed tests found.

Files with missing lines Patch % Lines
src/sentry/event_manager.py 90.00% 1 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##           master   #95402      +/-   ##
==========================================
- Coverage   87.84%   82.88%   -4.97%     
==========================================
  Files       10502    10457      -45     
  Lines      608126   605810    -2316     
  Branches    23719    23710       -9     
==========================================
- Hits       534228   502133   -32095     
- Misses      73540   103319   +29779     
  Partials      358      358              

@cvxluo cvxluo marked this pull request as ready for review July 14, 2025 02:19
@cvxluo cvxluo requested a review from a team as a code owner July 14, 2025 02:19
cursor[bot]

This comment was marked as outdated.

Copy link
Member

@yuvmen yuvmen left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

looks good :), just a minor comment about a comment, might want to let Katie approve as well before you merge

@cvxluo cvxluo requested a review from lobsterkatie July 14, 2025 18:49
def _set_project_platform_if_needed(project: Project, event: Event) -> None:
# Only infer the platform if it's useful - if the event platform is "other" or null, there's
# no useful information for us to set the project platform
if not event.platform or event.platform == "other":
Copy link
Member

@mrduncan mrduncan Jul 14, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should exclude "other" here, users can explicitly select this during project creation by searching for it and we shouldn't overwrite it:

Screenshot 2025-07-14 at 12 51 54 PM

Copy link
Contributor Author

@cvxluo cvxluo Jul 14, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

here, we exclude events without a platform - we won't overwrite platform if it is set anywhere
the motivation to exclude 'other' events is that in cases where an event is missing a platform, it seems to get normalized to 'other'. in those cases, i'd rather ignore the event and do nothing rather than assign the project to 'other'

cursor[bot]

This comment was marked as outdated.

cursor[bot]

This comment was marked as outdated.

cursor[bot]

This comment was marked as outdated.

cursor[bot]

This comment was marked as outdated.

cursor[bot]

This comment was marked as outdated.

@cvxluo cvxluo requested a review from a team July 15, 2025 23:28
cursor[bot]

This comment was marked as outdated.

Comment on lines +703 to +707
if project.platform:
return

if event.platform not in VALID_PLATFORMS or event.get_tag("sample_event") == "yes":
return
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nit: Could combine this into the same if

Copy link

@cursor cursor bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Bug: In-memory Project Platform Not Updated Post-Database Write

When a project's platform is inferred and updated in the database, the in-memory project object's platform attribute is not refreshed. This results in stale project.platform data (None or empty string) for subsequent operations within the same request, even though the database has been correctly updated. The fix involves updating the in-memory project.platform attribute after the successful database write.

src/sentry/event_manager.py#L709-L720

try:
updated = Project.objects.filter(
Q(id=project.id) & (Q(platform__isnull=True) | Q(platform=""))
).update(platform=event.platform)
if updated:
create_system_audit_entry(
organization=project.organization,
target_object=project.id,
event=audit_log.get_event_id("PROJECT_EDIT"),
data={**project.get_audit_log_data(), "platform": event.platform},
)

Fix in CursorFix in Web


Was this report helpful? Give feedback by reacting with 👍 or 👎

@cvxluo cvxluo merged commit 975b000 into master Jul 16, 2025
64 checks passed
@cvxluo cvxluo deleted the cvxluo/infer-project-platform branch July 16, 2025 20:04
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Scope: Backend Automatically applied to PRs that change backend components
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants